feat(agent): add custom_validator hook with retry to AsyncAgent.query#77
Merged
Conversation
Adds an optional `custom_validator` callable (and `max_validation_retries`) parameter to `AsyncAgent.query`. When supplied, the validator is invoked with each LLM result; if it returns a non-empty feedback string, the prompt is re-issued with the feedback appended so the LLM can self-correct. Bounded by `max_validation_retries` (default 2 extra calls). This is useful for callers that need a structural / semantic check that strict_json's schema enforcement can't express — for example, validating that every UUID the LLM emits belongs to a known input set. Defaults preserve existing behavior (no validator, single call). Bumps version 3.4.3 -> 3.4.4.
nikhilb-lgtm
reviewed
Jun 8, 2026
nikhilb-lgtm
reviewed
Jun 8, 2026
nikhilb-lgtm
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
custom_validator+max_validation_retriesparameters toAsyncAgent.query. Validator (sync or async) inspects the LLM result; returning a feedback string triggers a re-prompt that includes the feedback so the LLM can self-correct. Bounded bymax_validation_retries(default 2 extra calls).Motivation
Consumer use case: SimbianOS filter-observables step where the LLM occasionally garbles a
hypothesis_result_idUUID by a single character, crashing downstream DAO lookups. With this hook the caller can pass a UUID-in-input-set validator and TaskGen handles the retry/feedback loop in one place instead of every caller wrappingqueryin their own retry helper. Tracking comment: https://github.com/simbianai/SimbianOS/pull/4702#discussion_r3288175018Test plan
AsyncAgent.querywith a validator that returnsNone(no retry, single call)